from django.db.models.signals import post_save, post_delete
from django.dispatch import receiver
from .models import MenuBarItems, MenuBarClass
from django.core.cache import cache
from loguru import logger


@receiver([post_save, post_delete], sender=MenuBarItems)
def handle_menu_item_change(sender, instance, **kwargs):
    cache.delete('database_search_cache:menu_bar_items')
    logger.debug(f'menu_bar_items表修改数据id={instance.id}，重置缓存')


@receiver([post_save, post_delete], sender=MenuBarClass)
def handle_menu_class_change(sender, instance, **kwargs):
    cache.delete('database_search_cache:menu_bar_class')
    logger.debug(f'menu_bar_class表修改数据id={instance.id}，重置缓存')
